package com.hm.shopping.auto.su.helper;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.hm.base.service.AuthorizationService;
import com.hm.core.ApiAspectSuport;
import com.hm.shopping.auto.SystemEnvConfigProperties;

/**
 * @author shishun.wang
 * @date 2018年1月29日 下午3:10:57
 * @version 1.0
 * @describe
 */
@Aspect
@Component
public class ApiAspectHandler {

	@Autowired
	private ApiAspectSuport apiAspectSuport;

	@Autowired
	private AuthorizationService authorizationService;

	@Autowired
	private SystemEnvConfigProperties systemEnvConfigProperties;

	@Around("execution(* com.hm.shopping.api.**Api.*(..))")
	public Object process(ProceedingJoinPoint point) throws Throwable {
		Method method = ((MethodSignature) point.getSignature()).getMethod();
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
		apiAspectSuport.process(method, request, authorizationService, systemEnvConfigProperties.isDevModel(), systemEnvConfigProperties.isOpenDataAuth());

		return point.proceed();
	}

}
